from django.db import models
from com.kjssoft.common.globals import DBTableAssist
from com.kjssoft.rainbow import LOGGER

__author__ = 'Sea'

class RainbowPhotoFrameCategory(models.Model):
    name           = models.CharField(max_length=500, unique=True)
    super_category = models.ForeignKey('category.RainbowPhotoFrameCategory', related_name='rainbow_photo_frame_super_category', null=True, blank=True)

    def _has(self):
        has_more = RainbowPhotoFrameCategory.objects.filter(
            super_category__in = RainbowPhotoFrameCategory.objects.filter(name = self.name)
        ).count() > 0
        if has_more:
            has_more = 1
        LOGGER.debug('%s has more category %s' % (self, has_more))
        return has_more
    has_more = property(_has)

    def __unicode__(self):
        return 'rainbow photo frame category %s(%s)' % (self.name, self.id)

    class Meta:
        db_table = DBTableAssist.get_db_table_name('rainbow_photo_frame_category')